/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package BLL;

import BE.Song;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;

/**
 *
 * @author notandi
 */
public class SongManager
{

    private static SongManager instance = null;

    private List<Song> songs;

    private SongManager()
    {
        songs = new ArrayList<>();
    }

    public static SongManager getInstance()
    {
        if (instance == null)
        {
            instance = new SongManager();
        }
        return instance;
    }

    public Song getById(int id)
    {
        for (Song s : songs)
        {
            if (s.getId() == id)
            {
                return s;
            }
        }
        return null;
    }

    public Song getByName(String title)
    {
        for (Song s : songs)
        {
            if (s.getTitle().equals(title))
            {
                return s;
            }
        }
        return null;
    }

    public Song getByBpm(int bpm)
    {
        for (Song s : songs)
        {
            if (s.getBpm() == bpm)
            {
                return s;
            }
        }
        return null;
    }

    public Song getByDuration(int duration)
    {
        for (Song s : songs)
        {
            if (s.getDuration() == duration)
            {
                return s;
            }
        }
        return null;
    }
    
    public Song getIsFavorite(Boolean favorite)
    {
        for (Song s: songs)
        {
            if(Objects.equals(s.getFavorite(), favorite))
            {
                return s;
            }
        }
        return null;
    }

    public final List<Song> getAll()
    {
        return songs;
    }
    
    public void addSong(Song s)
    {
        songs.add(s);
    }
    
    
}
